package org.example.chapter3_3.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.example.chapter3_3.entity.Card;
import org.example.chapter3_3.entity.student;

import java.util.List;

@Mapper
public interface StuMapper {

        @Select("select * from tb_student where name like concat('%',#{name},'%')")
        List<student> getStuByName(String name);
        @Result(property = "card",column = "no" ,one = @One(select = "org.example.chapter3_3.mapper.StuMapper.getCardByNo"))//包名+类名+方法名
        @Select("select * from tb_student where qq =#{qq}")
        List<student> getStuByQQ(String qq);

        @Select("select * from card where cardNo = #{no}")
        Card getCardByNo(String no);
        @Select({
                "<script>",
                "select * from tb_student where 1=1",
                "<if test='name != null'>",
                "and name = #{name}",
                "</if>",
                "<if test='no != null'>",
                "and no = #{no}",
                "</if>",
                "</script>"
        })
        List<student> getStuByNameOrNo(String name,String no);
}
